﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CoreLibrary.Concurrent {

    public class TaskUtil {

        public static void RunQuiet(Action action) {
            try {
               Task.Factory.StartNew(action).Start();
            } 
            catch (AggregateException exception) {
                // run quielty
            }
        }

        public static void Run(IEnumerable<Action> actions) {
            try {
                var tasks = actions.Select(action => Task.Factory.StartNew(action)).ToArray();
                Task.WaitAll(tasks);
            } 
            catch (AggregateException exception) {
                throw exception.Flatten();
            }
        }

    }

}